package edu.ustb.service.order.Impl;

import edu.ustb.domain.orders.OrderDetail;
import edu.ustb.domain.orders.Orders;
import edu.ustb.mapper.orders.OrderDetailDao;
import edu.ustb.mapper.orders.OrdersDao;
import edu.ustb.service.order.OrderService;
import edu.ustb.utils.MybatisUtil;

import java.util.List;

public class OrderServiceImpl implements OrderService {

    @Override
    public List<Orders> findByPhone(String userPhone) {
        OrdersDao ordersDao = MybatisUtil.getMapper(OrdersDao.class);
        // TODO
        System.out.println("service phone"+userPhone);
        List<Orders> ordersList = ordersDao.findByPhone(userPhone);
        System.out.println("service findByPhone :");
        System.out.println(ordersList);
        MybatisUtil.commit();
        MybatisUtil.close();
        return ordersList;
    }

    @Override
    public List<OrderDetail> findDetailByOrserID(String orderId) {
        OrderDetailDao orderDetailDao = MybatisUtil.getMapper(OrderDetailDao.class);
        //TODO
        List<OrderDetail> orderDetailList = orderDetailDao.findDetailByOrserID(orderId);
        MybatisUtil.commit();
        MybatisUtil.close();
        return orderDetailList;
    }

    @Override
    public List<Orders> findBySta(String userPhone, String orderStatus) {
        OrdersDao ordersDao = MybatisUtil.getMapper(OrdersDao.class);
        // TODO
        System.out.println("service phone"+userPhone);
        List<Orders> ordersList = ordersDao.findBySta(userPhone,Integer.parseInt(orderStatus));
        System.out.println("service findByStat :");
        System.out.println(ordersList);
        MybatisUtil.commit();
        MybatisUtil.close();
        return ordersList;
    }
}
